#coding=utf-8
"""
Author:杭州多测师_周sir
Time:2025/8/28 10:36
website:https://duoceshi.net
"""

'''
pip install pyyaml
'''
import yaml
from config.config import *
import os

class Read_Yaml():
    def __init__(self,file_path):
        '''
        接受yaml文件作为参数
        '''
        self.file_path = file_path
        self.data = None

    def load_data_yaml(self):
        '''
        加载yaml文件内容
        :return:
        '''
        try:
            with open(self.file_path,'r',encoding="utf-8") as f:
                self.data = yaml.safe_load(f)
            print("YAML 加载成功")
        except FileNotFoundError:
            print(f"错误：文件{self.file_path} 未找到")
        except yaml.YAMLError as e:
            print(f"错误：解析 YAML 文件时错误-{e}")
        except Exception as e:
            print(f"位置错误:{e}")

    def get_data_yaml(self):
        '''
        获取加载后的yaml数据
        :return:
        '''
        if self.data is None:
            print("尚未加载 YAML 文件 请先调用load_data_yaml 方法")
            return None
        return self.data

file = os.path.join(data_path,'data.yaml')
yaml_read = Read_Yaml(file)

# 加载yaml文件
yaml_read.load_data_yaml()

# 获取加载后的数据
data = yaml_read.get_data_yaml()
print(data['url'])





